package com.example.springblog.config;

import com.example.springblog.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@ControllerAdvice
@ResponseBody
@Slf4j
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handlerException(Exception e) {
        log.info("发生异常e: " + e);
        return Result.fail("内部错误, 请联系管理员!");
    }
    @ExceptionHandler
    public Result handlerNotSupportedException(HttpRequestMethodNotSupportedException exception) {
        return Result.fail("请求错误");
    }
    @ExceptionHandler
    public void handlerNoResourceFoundException(NoResourceFoundException exception) {
        log.info("未获取到图标");
    }
}
